;; -*- lexical-binding: t -*-
(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'cl-lib)
(require 'init-package)
(require 'init-base)

(use-package general
  :ensure t
  :config
  (general-evil-setup t))

;; (use-package magit)
;; (setq magit-git-executable "C:/Program Files/Git/bin/git.exe")

(require 'cnfonts)
;; 让 cnfonts 在 Emacs 启动时自动生效。
(cnfonts-mode 1)
;; 添加两个字号增大缩小的快捷键
(define-key cnfonts-mode-map (kbd "C--") #'cnfonts-decrease-fontsize)
(define-key cnfonts-mode-map (kbd "C-=") #'cnfonts-increase-fontsize)

(general-create-definer my-leader-def
  :states '(normal insert visual emacs)
  :prefix ","
  :non-normal-prefix "C-,")

(use-package ace-window
  :ensure t
  :after general
  :hook (dired-mode . (lambda ()
	    (setq-local aw-ignore-on t))) ;; dired-mode 下禁用 ace-window
  )

;; (use-package projectile
;;   :ensure t
;;   :bind (("C-c p" . projectile-command-map))
;;   :config
;;   (setq projectile-mode-line "Projectile")
;;   (setq projectile-trac(use-package counsel-projectile
;;   :ensure t
;;   :after (projectile)
;;   :init (counsel-projectile-mode))k-known-projects-automatically nil))

;; (use-package counsel-projectile
;;   :ensure t
;;   :after (projectile)
;;   :init (counsel-projectile-mode))

;; (use-package treemacs
;;   :ensure t
;;   :defer t
;;   :config
;;   (treemacs-tag-follow-mode)
;;   :bind
;;   (:map global-map
;;         ("M-0"       . treemacs-select-window)
;;         ("C-x t 1"   . treemacs-delete-other-windows)
;;         ("C-x t t"   . treemacs)
;;         ("C-x t B"   . treemacs-bookmark)
;;         ;; ("C-x t C-t" . treemacs-find-file)
;;         ("C-x t M-t" . treemacs-find-tag))
;;   (:map treemacs-mode-map
;; 	("/" . treemacs-advanced-helpful-hydra)))

;; (use-package treemacs-evil
;;   :after (treemacs evil)
;;   :ensure t)

;; (use-package treemacs-projectile
;;   :ensure t
;;   :after (treemacs projectile))

(use-package neotree
  :config
  (my-leader-def
    "tt" 'neotree-toggle
    "a"  'neotree-create-node
    "d"  'neotree-delete-node
    "r"  'neotree-rename-node
    "p"  'neotree-copy-node
    "s"  'find-file-other-window
    "o"  'neotree-enter)
  (setq neo-theme (if (display-graphic-p) 'nerd-icons 'arrow)))

(use-package awesome-tab
  :load-path "~/.emacs.d/lisp/awesome-tab"
  :after general
  :custom
  (awesome-tab-show-tab-index 1)
  :config
  (awesome-tab-mode t)
  (my-leader-def
    :states 'normal
    "bp" #'awesome-tab-ace-jump
    "bd" #'awesome-tab-kill-other-buffers-in-current-group
    ; "gT" #'awesome-tab-backward-tab
    ; "gt" #'awesome-tab-forward-tab
    "1" #'awesome-tab-select-visible-tab
    "2" #'awesome-tab-select-visible-tab
    "3" #'awesome-tab-select-visible-tab
    "4" #'awesome-tab-select-visible-tab
    "5" #'awesome-tab-select-visible-tab
    "6" #'awesome-tab-select-visible-tab
    "7" #'awesome-tab-select-visible-tab
    "8" #'awesome-tab-select-visible-tab
    "9" #'awesome-tab-select-visible-tab))

(add-hook 'prog-mode-hook #'hs-minor-mode)
(my-leader-def
  :states 'normal
  "<SPC>" 'hs-toggle-hiding) ;; 切换当前代码块的折叠/展开状态
(global-set-key (kbd "C-c h") 'hs-hide-block) ;; 折叠当前代码块
(global-set-key (kbd "C-c s") 'hs-show-block) ;; 展开当前代码块
(global-set-key (kbd "C-c a") 'hs-hide-all) ;; 折叠所有代码
(global-set-key (kbd "C-c r") 'hs-show-all) ;; 展开所有代码
(global-set-key (kbd "C-c t") 'hs-toggle-hiding) ;; 切换当前代码块的折叠/展开状态

(use-package evil-nerd-commenter
  :after (evil)
  :ensure t
  :config
  (evilnc-default-hotkeys))

(use-package evil-surround
  :ensure t
  :config
  (global-evil-surround-mode t))

;; (use-package avy
;;   :ensure t
;;   :after general ;; 确保 general 插件已经安装
;;   :config
;;   (setq avy-timeout-seconds 0.5)
;;   (my-leader-def
;;     "f" 'avy-goto-char-timer))

;; (use-package ivy
;;   :ensure t
;;   :diminish ivy-mode
;;   :hook (after-init . ivy-mode))

(use-package indent-guide
  :ensure t
  :init
  (indent-guide-global-mode)
  ;; :config
  ;; (set-face-background 'indent-guide-face "dimgray")
  ;; (setq indent-guide-delay 0.1)
  ;; (setq indent-guide-char ".")
  ;; (setq indent-guide-recursive t)
  )

;; (require 'smart-align)
;; (defun vim-easy-align (beg end)
;;   (interactive "r")
;;   (align-regexp beg end "\\(\\w+\\)" -1 0 1))
(my-leader-def "ga" 'align-regexp)

(evil-ex-define-cmd "sp"  'split-window-below)
(evil-ex-define-cmd "vsp" 'split-window-right)
(evil-define-key 'normal 'global (kbd "C-;") 'ace-window)
(evil-define-key 'normal 'global (kbd "C-l") 'evil-window-right)
(evil-define-key 'normal 'global (kbd "C-h") 'evil-window-left)
(evil-define-key 'normal 'global (kbd "C-j") 'evil-window-down)
(evil-define-key 'normal 'global (kbd "C-k") 'evil-window-up)

;; 正确处理驼峰命名的单词
(use-package subword
  :hook (after-init . global-subword-mode))

;; 显示空白字符
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(use-package whitespace
  :ensure nil
  :hook ((prog-mode markdown-mode conf-mode) . whitespace-mode)
  :config
  (setq whitespace-style '(face trailing)))

(use-package corfu
  :custom
  (corfu-cycle t) ;; 启用循环
  (corfu-quit-at-boundary nil) ;; 不在补全边界退出
  (corfu-quit-no-match nil) ;; 即使没有匹配项也不退出
  (corfu-preview-current nil) ;; 禁用当前候选项预览
  (corfu-preselect 'prompt) ;; 预选提示
  :hook ((prog-mode . corfu-mode)
	 (shell-mode . corfu-mode)
	 (eshell-mode . corfu-mode))
  :init
  (global-corfu-mode))

(use-package yasnippet
  :ensure t
  :hook ((after-init . yas-reload-all)
	 ((prog-mode) . yas-minor-mode))
  :config
  (setq yas-snippet-dirs
	'("~/.emacs.d/snippets")))

;; (use-package treesit-auto
;;   :custom
;;   (treesit-auto-install 'prompt)
;;   :config
;;   (global-treesit-auto-mode))

(require 'python-mode)
(require 'skill-mode)
;; (require 'memo-mode)
;; (require 'my-special-mode)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-safe-themes
   '("0325a6b5eea7e5febae709dab35ec8648908af12cf2d2b569bedc8da0a3a81c1"
     "fd22a3aac273624858a4184079b7134fb4e97104d1627cb2b488821be765ff17"
     default))
 '(package-selected-packages nil))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
